<?php 
//Luu giu trang thai loc theo loai ho so
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_recordtype_filter = $_REQUEST['hdn_recordtype_filter'];
} 
//Begin//Xay dung chuoi XML chua gi tri 
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}

$v_record_id = 0;
if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id = intval($_REQUEST['hdn_record_id']);
}
$v_received_date = "";
if(isset($_REQUEST['txt_received_date'])){
	$v_received_date = $_REQUEST['txt_received_date'];
}
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_fk_recordtype = $_REQUEST['hdn_recordtype_filter'];
}

$strXML = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';

//Tinh so luong hs canh bao
$v_arrs_warning=Query_Data_For_Colunm_name("select count(*) AS SUM_WARNING from T_ONEGATE_RECORD_CONFLICTRECORD where fk_record_conflic='$v_record_id'");
$v_count_warning=$v_arrs_warning[0]['SUM_WARNING'].'<br/>';
//echo $v_count_warning.'<br/>';
if($v_count_warning<=0){
	for ($i=0;$i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR);$i++){
		$strXML = $strXML ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
		$strXML = $strXML .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
		$strXML = $strXML ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	}
	//echo $strXML;exit;
}else{
	$arr_single_conflict = Query_Data_For_Colunm_name("Select * From T_ONEGATE_CONFLICTRECORD Where PK_RECORDCONFLICT ='$v_record_id'");
	$v_xml_str = $arr_single_conflict[0]['C_RECORD_XML_DATA'];
	$v_user_name_chong=_XML_get_xml_tag_value($v_xml_str,'user_name_chong');
	$v_user_name_vo=_XML_get_xml_tag_value($v_xml_str,'user_name_vo');
	
	for ($i=0;$i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR);$i++){
		$tag_xml_i=_list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR);
		$value_tag_xml_i=_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR);
		
		$strXML = $strXML ."<".$tag_xml_i.">";
		
		if($tag_xml_i=='user_name_chong'){
			$strXML = $strXML .trim(_replace_XML_bad_char($v_user_name_chong));	
		}else if($tag_xml_i=='user_name_vo'){
			$strXML = $strXML .trim(_replace_XML_bad_char($v_user_name_vo));	
		}else{
			$strXML = $strXML .trim(_replace_XML_bad_char($value_tag_xml_i));
		}
		
		$strXML = $strXML ."</".$tag_xml_i.">";
	}
	//echo 'xml_warning='.$strXML;exit;
}
$strXML = $strXML . "</data_list></root>";
$strXML = str_replace("'","",$strXML);

$v_status = $arr_record_status[0][0];
$v_recordtype = $_SESSION['onegate_current_recordtype'];
$v_receiver = $_SESSION['staff_id'];

if(_is_sqlserver()){
	$license_xml_data_id = _save_XML_to_database('T_TEMP_FILE', 'PK_TEMP_FILE', 'C_TEXT', $strXML);
	
	if($v_record_id <= 0){
		$sql = "insert into T_ONEGATE_CONFLICTRECORD values ('";
		$sql=$sql._ddmmyyyy_to_yyyymmdd($v_received_date)."'";
		$sql=$sql.",'TRANH_CHAP'";
		$sql=$sql.",'".$strXML."'";
		$sql=$sql.",".$v_receiver;
		$sql=$sql.",'"._ddmmyyyy_to_yyyymmdd($v_received_date)."')";
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql); 
		$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	}else{
		$sql= "update T_ONEGATE_CONFLICTRECORD set C_RECORD_XML_DATA= '".$strXML."' where PK_RECORDCONFLICT=".$v_record_id;
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql); 
		$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	}

}
sleep(0);
if (!is_null($v_error) && $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_goto_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="DISPLAY_ALL_RECORD_FOR_DISPUTE">
	<input type="hidden" name="hdn_record_id" value="<?php echo $v_record_id;?>">
	<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
</form>
<Script language="javascript">
	document.forms(0).submit();
</Script>